//
//  AutoSrcollView.swift
//  FeastBooking
//
//  Created by Imon on 2017/9/3.
//  Copyright © 2017年 Imon. All rights reserved.
//

import UIKit
import Kingfisher

class AutoScrollView: UIScrollView {
    
    let loadingAD: UIImage = UIImage(named: "loading")!
    
    func createUI(urls: [String]) {
        var urls = urls //让images可修改
        let width = self.bounds.width
        let height = self.bounds.height
        
        let first = urls[0]
        let last = urls[urls.count - 1]
        
        urls.insert(last, at: 0)
        urls.append(first)
        
        for i in 0...(urls.count - 1) {
            let imageView = UIImageView(frame: CGRect(x: CGFloat(i) * width, y: 0, width: width, height: height))
            imageView.contentMode = .scaleAspectFill
            imageView.layer.masksToBounds = true
            let url = URL(string: urls[i])
            imageView.kf.setImage(with: url, placeholder: loadingAD)
            self.addSubview(imageView)
        }
        self.contentSize = CGSize(width: CGFloat(urls.count) * width, height: height)
        //设置属性
        self.showsVerticalScrollIndicator = false
        self.showsHorizontalScrollIndicator = false
        self.isScrollEnabled = true
        self.isPagingEnabled = true
        self.scrollsToTop = false

    }
}
